package main.java.chessfootball.model.game;

/**
 * User: Igor
 * Date: 13.06.2011
 * Time: 21:39:56
 */
public class Area
{
	private Cell[] area = new Cell[2];

	public Area(int x, int y, int length, int width)
	{
		area[0] = new Cell(x, y);
		area[1] = new Cell(x + length - 1, y + width - 1);
	}

	public Cell[] getArea()
	{
		return area;
	}

	public int getX()
	{
		return area[0].getX();
	}

	public int getY()
	{
		return area[0].getY();
	}

	public int getLength()
	{
		return area[1].getX() - area[0].getX();
	}

	public int getWidth()
	{
		return area[1].getY() - area[0].getY();
	}

	public int getX2()
	{
		return area[1].getX();
	}

	public int getY2()
	{
		return area[1].getY();
	}

	public boolean contains(Cell cell)
	{
		return !((cell.getX() < area[0].getX())
				|| (cell.getX() > area[1].getX())
				|| (cell.getY() < area[0].getY())
				|| (cell.getY() > area[1].getY()));
	}

	public boolean containsByX(Cell cell)
	{
		return !((cell.getX() < area[0].getX())
				|| (cell.getX() > area[1].getX()));
	}

	public boolean containsByY(Cell cell)
	{
		return !((cell.getY() < area[0].getY())
				|| (cell.getY() > area[1].getY()));
	}

	public Area invert()
	{
		return new Area(Field.LENGTH - getX2() - 1, Field.WIDTH - getY2() - 1, getLength(), getWidth());	
	}
}
